﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ymatou.User.Common.UserEnum;
using Ymatou.User.Dto;
using Ymatou.User.Dto.Auth;
using Ymatou.User.ServerResponse;

namespace Ymatou.UserAuth.Agent.Login
{
    /// <summary>
    /// 登录认证agent api
    /// </summary>
    public interface IUserLoginAuthAgent
    {

        /// <summary>
        /// 根据用户手机获取loginId修改次数
        /// </summary>
        /// <param name="mobile">mobile</param>
        /// <param name="actionSource">actionSource</param>
        /// <returns></returns>
        long GetModifyLoginIdCountByMobile(string mobile, UserRegSource actionSource = UserRegSource.App);
        /// <summary>
        /// 根据用户ID获取loginId修改次数
        /// </summary>
        /// <param name="userId">userId</param>
        /// <param name="actionSource">actionSource</param>
        /// <returns></returns>
        long GetModifyLoginIdCountByUserId(int userId, UserRegSource actionSource = UserRegSource.App);
        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="userId"></param>      
        /// <returns></returns>
        ResponseData<UserBillsResponseDto> GetBuserBills(int userId/*, bool wirteSession = true*/);
        /// <summary>
        /// 用户登出
        /// </summary>
        void LogOut();
        /// <summary>
        /// 用户从cookie登录 。通过认证后返回用户Id，否则返回-1
        /// </summary>
        /// <returns></returns>
        int LoginByCookie(bool redirectLoginPage = false, bool redirectOpenAuth = false);
        /// <summary>
        /// 用户登录认证并修改登录token。认证通过后返回用户Id
        /// </summary>
        /// <param name="loginId">洋码头用户ID或者手机或者登录邮箱</param>
        /// <param name="password"></param>
        /// <param name="upToken">登录成功后更新用户登录token；token 返回用户类型</param>
        /// <param name="sourceType">登录来源：www.ymatou.com ，app，dms，xxx.admin,ali,weibo（必填）</param>
        /// <param name="tokenTimeOut">保存凭据超时时间</param>
        /// <returns></returns>
        ResponseData<LoginAuthResponseDto2> LoginAuth(string loginId, string password, Func<int, int> upToken, string sourceType, TimeSpan? tokenTimeOut = null);
        /// <summary>
        /// 用户登录认证。认证通过后返回用户Id
        /// </summary>
        /// <param name="loginId">洋码头用户ID或者手机或者登录邮箱</param>
        /// <param name="password"></param> 
        /// <param name="sourceType">登录客户端类型：www.ymatou.com ，app，dms，xxx.admin,ali,weibo（必填）</param>
        /// <param name="tokenTimeOut">保存凭据超时时间</param>
        /// <returns></returns>
        ResponseData<LoginAuthResponseDto2> LoginAuth(string loginId, string password, string sourceType = "", TimeSpan? tokenTimeOut = null);
        /// <summary>
        /// 单点登录认证
        /// </summary>
        /// <param name="loginId">洋码头用户ID或者手机或者登录邮箱</param>
        /// <param name="password"></param>
        /// <param name="sourceType">登录客户端类型：www.ymatou.com ，app，dms，xxx.admin,ali,weibo（必填）</param>
        /// <param name="tokenTimeOut">保存凭据超时时间</param>
        /// <returns></returns>
        ResponseData<LoginAuthResponseDto2> SSOLoginAuth(string loginId, string password, string sourceType = "", TimeSpan? tokenTimeOut = null);
        /// <summary>
        /// 获取用户凭据
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="loginPassword"></param>
        /// <returns></returns>
        ResponseData<UserBillsResponseDto> GetUserBills(int userId, string loginPassword = "");
        /// <summary>
        /// 更新用户登录凭据（loginId，登录邮箱，登录手机）
        /// </summary>
        /// <param name="iUserId"></param>
        /// <param name="newKey"></param>
        /// <param name="type"></param>
        void UpdateLoginBills(int iUserId, string newKey, LoginKeyType type);
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="iUserId"></param>
        /// <param name="newPas"></param>
        /// <param name="oldPas"></param>
        /// <param name="pasType"></param>
        ResponseData<ResetPasswordReponseCode> ChangPassword(int iUserId, string newPas, string oldPas, PasswordActionType pasType, ActionType aType = ActionType.ByUserId, string loginMobile = null);
        /// <summary>
        /// 修改交易密码
        /// </summary>
        /// <param name="iUserId"></param>
        /// <param name="newTPas"></param>
        /// <param name="oldTPas"></param>
        /// <param name="aType"></param>
        /// <returns></returns>
        ResponseData<ResetPasswordReponseCode> ChangTradingPassword(int iUserId, string newTPas, string oldTPas = null, ActionType aType = ActionType.ByUserId);
        /// <summary>
        /// 修改登录密码
        /// </summary>
        /// <param name="iUserId"></param>
        /// <param name="newLPas"></param>
        /// <param name="oldLPas"></param>
        /// <param name="aType"></param>
        /// <returns></returns>
        ResponseData<ResetPasswordReponseCode> ChangLoginPassword(int iUserId, string newLPas, string oldLPas = null, ActionType aType = ActionType.ByUserId);
        /// <summary>
        /// 根据登录手机修改密码
        /// </summary>
        /// <param name="loginMobile">作为登录凭证的手机号</param>
        /// <param name="newPas"></param>
        ResponseData<ResetPasswordReponseCode> ChangLoginPasswordByMobile(string loginMobile, string newPas);

        /// <summary>
        /// 修改登录token
        /// </summary>
        /// <param name="iUserId"></param>
        /// <param name="userType"></param>
        /// <param name="loginTime"></param>
        void UpdateUserLoginToken(int iUserId, int userType, string loginTime);
        /// <summary>
        /// 异步修改客户端登录token
        /// </summary>
        /// <param name="iUserId"></param>
        /// <param name="userType"></param>
        /// <param name="loginTime"></param>
        void UpdateUserLoginTokenAsync(int iUserId, int userType, string loginTime);
        /// <summary>
        /// 获取用户在规定时间内的登录失败次数
        /// </summary>
        /// <param name="loginId"></param>
        /// <param name="timeSpan">分钟：-5 即 5分钟内</param>
        /// <returns></returns>
        int GetUserLoginFailCount(string loginId, int timeSpan = -5);
        /// <summary>
        /// 获取用户登录邮箱认证通知
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        bool MailAuthNotice(int userId);
        /// <summary>
        /// 用户是否第一次绑定手机
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        bool UserFirstBindMobile(int userId);
        /// <summary>
        /// 检查用户是否存在
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="loginPassword"></param>
        /// <returns></returns>
        bool CheckUserLoginPassword(int userId, string loginPassword);
        /// <summary>
        /// 创建用户新凭据
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="loginId"></param>
        /// <param name="loginPassword"></param>
        /// <param name="mail"></param>
        /// <param name="mobile"></param>
        /// <param name="tradingPassword"></param>
        /// <returns></returns>
        ResponseData<string> CreateUserBills(int userId, string loginId, string loginPassword, string mail = null, string mobile = null, string tradingPassword = null, bool isYmtLogin = false);
        /// <summary>
        /// 根据手机号修改密码
        /// </summary>
        /// <param name="mobile">手机号</param>
        /// <param name="newLoginId">新用户名</param>
        /// <param name="actionSoure">操作来源（必填）</param>
        /// <returns></returns>
        ResponseData<BaseResponse> ChangLoginIdByMobile(string mobile, string newLoginId, UserRegSource actionSoure = UserRegSource.MainSite);
        /// <summary>
        /// 根据userID修改登录ID
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="newLoginId"></param>
        /// <param name="actionSoure"></param>
        /// <returns></returns>
        ResponseData<BaseResponse> ModifyUserLoginIdByUserId(int userId, string newLoginId, UserRegSource actionSoure = UserRegSource.MainSite);
    }
}
